package com.surfilter.mq.util.properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 获取上下文中properties属性值类
 *
 */
public class CustomizedPropertyConfigurer extends PropertyPlaceholderConfigurer{
	private static Map<String, Object> ctxPropertiesMap;

	@Override
	protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,Properties props) throws BeansException {
		super.processProperties(beanFactoryToProcess, props);
		ctxPropertiesMap=new HashMap<String, Object>();
		for (Object key:props.keySet()) {
			String keyString=key.toString();
			String valueString=props.getProperty(keyString);
			ctxPropertiesMap.put(keyString, valueString);
		}
	}
	
	/**
	 * 根据那么获取系统启动时加载的properties文件中各个属性值
	 * @param name 属性名
	 * @return
	 * 属性值
	 */
	public static Object getContextProperty(String name){
		return ctxPropertiesMap.get(name);
	}
}
